<template>
  <div>
    <el-input style="width: 200px" placeholder="查询模块" v-model="operation"></el-input>
    <el-button type="primary" style="margin-left: 10px" @click="load(1)">查询</el-button>
    <el-button type="info" @click="reset">重置</el-button>
  </div>
  <div style="margin: 10px 0">
    <el-button type="danger" plain @click="delBatch">批量删除</el-button>
  </div>
  <el-table :data="tableData" stripe :header-cell-style="{background:'aliceblue',color:'#666'}" @selection-change="handleSelectionChange">
    <el-table-column type="selection" width="55" align="center"></el-table-column>
    <el-table-column prop="id" label="序号" width="70" align="center"></el-table-column>
    <el-table-column prop="operation" label="操作模块"></el-table-column>
    <el-table-column prop="type" label="操作类型">
      <template v-slot="scope">
        <el-tag type="primary"></el-tag>
      </template>
    </el-table-column>
    <el-table-column prop="ip" label="操作人IP"></el-table-column>
    <el-table-column prop="user" label="操作人"></el-table-column>
    <el-table-column prop="time" label="操作时间"></el-table-column>
    <el-table-column label="操作" width="180" align="center">
      <template v-slot="scope">
        <el-button size="mini" type="danger" plain @click="del(scope.row.id)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>

  <div style="margin: 10px 0">
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-size="pageSize"
      layout="total, prev, pager, next"
      :total="total">
    </el-pagination>

  </div>
</template>
<script>


export default {
  name: 'Log',
  data() {
    return {
      tableData: [],
      pageNum:1,
      pageSize:5,
      operation: '',
      total: 0,
      form: {},
      user: JSON.parse(loaclStorage.getItem('honey-user')||'{}'),// 获取当前登录用户
      ids: [],//
    }
  },
  created() {
    this.load()
  },
  methods: {
    delBatch() {
      if (!this.ids.length) {
        this.$message.warning('请选择要删除的数据')
        return
      }
      this.$confirm('确定要删除吗？', '确认删除', {type: "warning"}).then(response => {
        this.$request.delete('logs/delete/batch', {data: this.ids}).then(res => {
          if (res.code === '200') {
            this.$message.success('操作成功')
            this.load()
          } else {
            this.$message.error(res.msg)
          }
        })
      }).catch(() => {
      })
    },
    handleSelectionChange(rows) {//当前选中的所有的行数据
      this.ids = rows.map(v => v.id)
    },
    del(id) {
      this.confirm.get('确定要删除吗？', '确认删除', {type: "warning"}).then(response => {
        this.$request.delete('/los/delete/' + id).then(res => {
          if (res.code === '200') {
            this.$message.success('操作成功')
            this.load(1)
          } else {
            this.$message.error(res.msg)
          }
        })
      }).catch(() => {
      })
    },
    reset() {
      this.operation = ''
      this.load()
    },
    load(pageNum) {
      if (pageNum) this.pageNum = pageNum
      this.$request.get('/logs/queryPage', {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          operation: this.operation
        }
      }).then(res => {
        this.tableData = res.data.records
        this.total = res.data.total
      })
    },
    handleCurrentChange(pageNum) { //分页
      this.load(pageNum)
    },
  }
}
</script>
<style>
.el-tooltip__popper {max-width: 300px !important;}
</style>